<?php
$no_visible_elements=true;
include_once('lib/Sqlexecutor.php');
include_once('lib/User.php');
session_start();
$username = isset($_POST['username']) ? $_POST['username'] : false;
$password = isset($_POST['password']) ? $_POST['password'] : false;
if($username && $password)
{
    $dbh = new Sqlexecutor('localhost', 'tile', 'tile', 'tile');
    $u = new User($dbh);
    $res = $u->login($username, $password);
    var_dump($res);
    if(is_array($res))
    {
        $_SESSION['username'] = $_POST['username'];
        header('Location:index.php');
    }
    else
    {
        $errno = $res;
    }
}


include('header.php'); ?>

			<div class="row-fluid">
				<div class="span12 center login-header">
					<h2>吉百旺瓷砖管理系统</h2>
				</div><!--/span-->
			</div><!--/row-->
			
			<div class="row-fluid">
				<div class="well span5 center login-box">
					<div class="alert alert-info">
					请使用用户名密码登录系统	
					</div>
					<form id="loginForm" class="form-horizontal" action="login.php" method="post">
						<fieldset>
                              <?php if($errno == -100) {?>  
                              <div class="alert alert-error">
                                <button type="button" class="close" data-dismiss="alert">×</button>
                                系统内部错误，请稍后重试，或者联系管理员. 
                              </div>
                              <?php }?>

                              <?php if($errno == -1) {?>  
                              <div class="alert alert-error">
                                <button type="button" class="close" data-dismiss="alert">×</button>
                                您输入的用户名和密码错误，请核实后重新登录. 
                              </div>
                              <?php }?>

							<div class="input-prepend" title="用户名" data-rel="tooltip">
								<span class="add-on"><i class="icon-user"></i></span><input class="input-large span10" name="username" id="username" type="text" value="admin" />
							</div>
							<div class="clearfix"></div>

							<div class="input-prepend" title="密码" data-rel="tooltip">
								<span class="add-on"><i class="icon-lock"></i></span><input autofocus class="input-large span10" name="password" id="password" type="password" value="" />
							</div>
							<div class="clearfix"></div>
<!--
							<div class="input-prepend">
							<label class="remember" for="remember"><input type="checkbox" id="remember" />记住密码</label>
							</div>
							<div class="clearfix"></div>
-->
							<p class="center span5">
							<button type="submit" class="btn btn-primary">登录</button>
							</p>
						</fieldset>
					</form>
				</div><!--/span-->
			</div><!--/row-->
<?php include('footer.php'); ?>

<script>
$().ready(function() {
	// validate signup form on keyup and submit
	$("#loginForm").validate({
		rules: {
			username: "required",
			password: {
				required: true,
				minlength: 6
			},
		},
		messages: {
			username: "请输入用户名",
			password: {
				required: "请输入密码",
				minlength: "密码至少6位"
			},
		}
	});
});
</script>

<style type="text/css">
form.form-horizontal label.error, label.error {
    /* remove the next line when you have trouble in IE6 with labels in list */
    color: #bd4247;
    font-style: italic
}
</style>
